﻿using Clancy.Data;
using System.Drawing;
using System.Windows.Controls;
using Rectangle = System.Windows.Shapes.Rectangle;

namespace Clancy.Common
{
    public static class RectangleExtensions
    {
        public static System.Windows.Point GetAnchorPoint(this Rectangle rectangle)
        {
            double left = Canvas.GetLeft(rectangle);
            double top = Canvas.GetTop(rectangle);
            return new System.Windows.Point(left, top);
        }

        public static void SetPosition(this Rectangle rect, double x, double y)
        {
            Canvas.SetLeft(rect, x);
            Canvas.SetTop(rect, y);
        }

        public static void TakeValuesFromRectanlge(this MotionZone motionZone, Rectangle rectangle)
        {
            motionZone.X = (int)Canvas.GetLeft(rectangle);
            motionZone.Y = (int)Canvas.GetTop(rectangle);
            motionZone.Width = (int)rectangle.Width;
            motionZone.Height = (int)rectangle.Height;
        }

        public static System.Drawing.Rectangle ToDrawingRectangle(this Rectangle shapeRectangle)
        {
            double left = Canvas.GetLeft(shapeRectangle);
            double top = Canvas.GetTop(shapeRectangle);
            return new System.Drawing.Rectangle((int)left, (int)top, (int)shapeRectangle.Height, (int)shapeRectangle.Width);
        }

        public static System.Drawing.Rectangle ToDrawingRectangle(this MotionZone motionZone)
        {
            System.Drawing.Rectangle newRectangle = new System.Drawing.Rectangle
            {
                X = motionZone.X,
                Y = motionZone.Y,
                Height = motionZone.Height,
                Width = motionZone.Width
            };

            return newRectangle;
        }

        public static MotionZone ToMotionZone(this System.Drawing.Rectangle drawingRectangle)
        {
            return new MotionZone(drawingRectangle.X, drawingRectangle.Y, drawingRectangle.Width, drawingRectangle.Height);
        }

        public static Rectangle ToShapesRectangle(this System.Drawing.Rectangle drawingRectangle)
        {
            Rectangle newRectangle = new Rectangle();
            Canvas.SetLeft(newRectangle, drawingRectangle.Left);
            Canvas.SetTop(newRectangle, drawingRectangle.Top);

            newRectangle.Height = drawingRectangle.Height;
            newRectangle.Width = drawingRectangle.Width;

            return newRectangle;
        }

        public static Rectangle ToShapesRectangle(this MotionZone motionZone)
        {
            Rectangle newRectangle = new Rectangle();
            Canvas.SetLeft(newRectangle, motionZone.X);
            Canvas.SetTop(newRectangle, motionZone.Y);

            newRectangle.Height = motionZone.Height;
            newRectangle.Width = motionZone.Width;

            return newRectangle;
        }
    }
}